/*
function generate_user_info(msg, remindid) {
	var user = eval("(" + msg + ")");
	user_array.push(user);
	$("#message-stream-item-" + remindid + " .message-nickname").qtip({
		content : user.nickname,
		style : {
			name : 'dark' // Inherit from preset style
		}
	});
}

function ajax_get_user_info(remindid, userid) {

	//alert(remindid);
	//alert(userid);

	var _ajax_get = true;
	for (x in user_array) {
		if (user_array[x].id == userid) {
			$("#message-stream-item-" + remindid + " .message-nickname").qtip({
				content : user_array[x].nickname,
				style : {
					name : 'dark' // Inherit from preset style
				}
			});
			_ajax_get = false;
			break;
		}
	}

	if (_ajax_get == true) {
		$.ajax({
			type : "GET",
			url : "servlet/GetUserInfo",
			data : "id=" + userID + "&searchid=" + userid + "&type=getInfo",
			success : function(msg) {
				generate_user_info(msg, remindid);
			}
		});
	}

}
 */

/**
 * 
 * <div class="stream-item"> <div class="more"></div> <div class="message">
 * <div class="message-image"> <img height="48" width="48"
 * src="http://a3.twimg.com/profile_images/1107286845/DW_speaking_normal.jpg"
 * alt="Dwyane Wade" class="user-profile-link" data-user-id="33995409"> </div>
 * <div class="message-content"> <div class="message-content-row"> <span
 * class="message-name"> <a class="message-nickname" href="">dwadeofficial</a>
 * <span class="message-realname">Dwyane Wade</span> </span> </div> <div
 * class="message-content-row"> <div class="message-info"> Reply to you in <a
 * href=""> j2ee���� </a> topic in <a href=""> j2ee </a> Group </div> </div>
 * <div class="message-content-row"> <div class="tweet-timestamp" title="1:15 PM
 * Jun 10th"> <span class="_old-timestamp" data-time="1307682947000"
 * data-long-form="true">10 Jun</span> </div> </div> </div> </div> </div>
 */

function generateReminds(msg) {
	// $("#message-stream-manager .ajax-preloader").remove();
	$("#message-stream-manager .ajax-preloader").empty();
	var reminds = eval("(" + msg + ")");
	for ( var i = 0; i < reminds.count; i++) {
		var remind = reminds.remind[i];
		remind_array.push(remind);
		var html = "<div class='stream-item' id='message-stream-item-"
				+ remind.id
				+ "' onclick='clickbutton(id)' onMouseOver='mouseover_stream(id)' onMouseOut='mouseout_stream(id)''><div class='more'></div>"
				+ "<div class='message'> <div class='message-image'>"
				+ "<img height='48' width='48' src='http://a3.twimg.com/profile_images/1107286845/DW_speaking_normal.jpg' alt='Dwyane Wade' class='user-profile-link' data-user-id='33995409'> </div> "
				+ "<div class='message-content'> <div class='message-content-row'>"
				+ "<span class='message-name'><a class='message-nickname' href='javascript:void(false)' onmouseover='ajax_get_user_info("
				+ remind.id
				+ ","
				+ remind.userFrom.id
				+ ")'> "
				+ remind.userFrom.nickname
				+ "</a><span class='message-realname'> "
				+ remind.userFrom.realname
				+ "</span> </span> </div> <div class='message-content-row'> <div class='message-info'> 在 <a class='message-info-topic' href='' owner='"
				+ remind.topic.owner
				+ "' time='"
				+ remind.topic.time
				+ "'> "
				+ remind.topic.title
				+ "</a> 中  <a href='' class='message-info-group'>"
				+ "</a> 回复了你 </div> </div> <div class='message-content-row'> <div class='tweet-timestamp' title='"
				+ remind.reply.time + "'> <span class='_old-timestamp'>"
				+ remind.reply.time
				+ "</span> </div> </div> </div> </div> </div>";

		$("#message-stream-manager .stream").append(html);
	}
}

function mouseover_stream(id) {
	$("#" + id).css("background-color", "#FBF393");
}

function mouseout_stream(id) {
	$("#" + id).css("background-color", "white");
}

/*
 * <div class="details-pane-outer" style="top: 65px;"> <div
 * class="details-pane-shell"> <div class="details-pane"> <div
 * class="inner-pane"> <div class="pane-toolbar"> <a class="pane-close">close
 * <span>��</span> </a> </div> <div class="pane-components"> <div
 * class="pane-components-inner"> <div class="component"> <div class="topic">
 * <div class="topic-title"> Topic Title </div> <div class="topic-info"> <a
 * href="#">Owner</a> <div> June 16th </div> </div> </div> </div> <div
 * class="component"> <hr class="component-spacer"> </div> <div
 * class="component"> <div class="reply-userfrom"> <a
 * class="reply-userfrom-username" data-user-id="228771545" href="/#!/Ruby_Tao"
 * title="Ruby">UserFrom</a> <span class="reply-userfrom-fullname">Fromer</span>
 * </div> </div> <div class="component"> <div class="reply-message"> <a
 * class="reply-userto-username" href=""> <span class="at">@KingJames</span>
 * </a> <span class="reply-message-content">every time is your time</span> <div
 * class="reply-timestamp"> Jun 16th </div> <span class="reply-actions"> <a
 * class="favorite-action" title="Favorite" rel="favorite"><b>Favorite</b>
 * </a> <a class="reply-action" data-screen-name="Ruby_Tao" title="Reply"
 * rel="reply"><b>Reply</b> </a> <a class="delete-action" title="Delete"
 * rel="delete"><b>Delete</b> </a> </span> </div> </div> </div> </div> </div>
 * </div> </div> </div>
 */
function clickbutton(id) {

	var remindid = id.slice(20);
	var should_show = false;

	if (currentRemindId != remindid) {
		should_show = true;
	} else {
		if (is_dashboard_out == false)
			should_show = true;
	}

	if (should_show == true) {
		$(".details-pane-outer").css("display", "none");
		var topictitle;// = $("#" + id + " .message-info-topic").text();
		var topicowner;// = $("#" + id + " .message-info-topic").attr("owner");
		var topictime;// = $("#" + id + " .message-info-topic").attr("time");
		var userFromNickname;// = $("#" + id + " .message-nickname").text();
		var userFromRealname;// = $("#" + id + " .message-realname").text();
		var replytime;// = $("#" + id + " ._old-timestamp").text();
		var contect;

		for (a in remind_array) {
			if (remind_array[a].id == remindid) {
				var remind = remind_array[a];
				content = remind.content;
				topictitle = remind.topic.title;
				topicowner = remind.topic.owner;
				topictime = remind.topic.time;
				userFromNickname = remind.userFrom.nickname;
				userFromRealname = remind.userFrom.realname;
				replytime = remind.reply.time;
				break;
			}
		}

		$(".details-pane-outer .topic-title").text(topictitle);
		$(".details-pane-outer .topic-info a").text(topicowner);
		$(".details-pane-outer .topic-info div").text(topictime);
		$(".details-pane-outer .reply-userfrom-username")
				.text(userFromNickname);
		$(".details-pane-outer .reply-userfrom-fullname")
				.text(userFromRealname);
		$(".details-pane-outer .reply-message-content").text(content);
		$(".details-pane-outer .reply-timestamp").text(replytime);

		$(".details-pane-outer").fadeIn();
		$(".details-pane").css("height", document.body.clientHeight - 80);
		$(".pane-components").css("height", document.body.clientHeight - 115);
		is_dashboard_out = true;
		currentRemindId = remindid;
	} else {
		$(".details-pane-outer").fadeOut();
		is_dashboard_out = false;
		currentRemindId = remindid;
	}
}

function close_dashboard() {
	$(".details-pane-outer").fadeOut();
	$.ajax({
		type : "POST",
		url : "servlet/SetReply",
		data : "type=delete&remindid=" + currentRemindId,
		success : function(msg) {
			if (msg == "delete success") {
				isotope_filter();
			}
		}
	});
	is_dashboard_out = false;
}

function isotope_filter() {
	$("#message-stream-item-" + currentRemindId).fadeOut();
}

/*
 * var managers = new Array( "message-stream-manager", "group-stream-manager",
 * "people-stream-manager", "favorites-stream-manager");
 */

/*
 * <div class='group-item'> <div class='more'></div> <div class='message'> <div
 * class='group-info'> <div class='group-name'> Python </div> <div
 * class='group-info-content'> <div class='group-info-row'> <a
 * class='group-owner'>owner</a> </div> <div class='group-info-row'> <div
 * class='tweet-timestamp' title='1:15 PM Jun 10th'> <span
 * class='_old-timestamp'>10 Jun</span> </div> </div> <div
 * class='group-info-row'> <div class='group-intro'> intro </div> </div> </div>
 * </div> <span class='function-button-bar'> <a href='javascript:void(false)'
 * class='css3button'><span class='cross icon'></span>Unfollow</a> <a
 * href='javascript:void(false)' class='css3button'><span class='rss icon'></span>Subscribe
 * to RSS Feed</a> <a href='javascript:void(false)' class='css3button'><span
 * class='comment icon'></span>Add Comment</a> </span> </div> </div> /
 * 
 */

// when mouse over follow button add green background just like twitter
// TODO Auto-generated
function follow_button_mouseover(id) {

}

function follow_button_mouseout(id) {

}

function generateGroups(msg) {
	$("#group-stream-manager .ajax-preloader").empty();
	var groups = eval("(" + msg + ")");
	for ( var i = 0; i < groups.count; i++) {
		var group = groups.group[i];
		group_array.push(group);
		var html = "<div class='group-item' id='group-stream-item-"
				+ group.id
				+ "' onMouseOver='mouseover_stream(id)' onMouseOut='mouseout_stream(id)'> <div class='more'></div> <div class='message'> <div class='group-info'> <div class='group-name'>"
				+ group.name
				+ " </div> <div class='group-info-content'> <div class='group-info-row'> <a class='group-owner'>"
				+ group.ownerNickname
				+ "</a> </div> <div class='group-info-row'> <div class='tweet-timestamp' title='1:15 PM Jun 10th'> <span class='_old-timestamp'>"
				+ group.time
				+ "</span> </div> </div> <div class='group-info-row'> <div class='group-intro'> "
				+ group.intro
				+ "</div> </div> </div> </div> <div class='function-button-bar'> <a href='javascript:void(false)' class='css3button' id='follow-button-"
				+ group.id
				+ "' onmouseover='follow_button_mouseover(id)' onmouseout='follow_button_mouseout(id)'><span class='cross icon'></span>Unfollow</a> <a href='javascript:void(false)' class='css3button'><span class='rss icon'></span>Subscribe to RSS Feed</a> <a href='javascript:void(false)' class='css3button'><span class='comment icon'></span>Add Comment</a> </div> </div> </div> ";
		$("#group-stream-manager .stream").append(html);
	}
}

/*
 * <div class='user-item'> <div class='more'></div> <div class='message'> <div
 * class='message-image'> <img height='48' width='48'
 * src='http://a3.twimg.com/profile_images/1107286845/DW_speaking_normal.jpg'>
 * </div> <div class='user-info-content'> <div class='user-info-row'> <span
 * class='user-name'> <a class='user-nickname'
 * href='javascript:void(false)'>dwadeofficial</a> <span
 * class='user-realname'>Dwyane Wade</span> </span> </div> <div
 * class='user-info-row'> <div class='email-info'> <span style='font-size: 17px
 * !important; font-weight : bold'>Email:</span> Ruby092977@gmail.com </div>
 * </div> <div class='user-info-row'> <div class='user-intro'> abc </div> </div>
 * </div> </div> </div>
 */

function generateUsers(msg) {
	$("#user-stream-manager .ajax-preloader").empty();
	var users = eval("(" + msg + ")");
	for ( var i = 0; i < users.count; i++) {
		var user = users.user[i];
		var follow_html;
		if (user.type == "0")
			follow_html = "<span class='cross icon'></span>Unfollow</a> <a href='javascript:void(false)' class='css3button'>";
		else
			follow_html = "<span class='loop icon'></span>Unfollow</a> <a href='javascript:void(false)' class='css3button'>";
		user_array.push(user);
		var html = "<div class='user-item' id='user-stream-item-"
				+ user.id
				+ "' onMouseOver='mouseover_stream(id)' onMouseOut='mouseout_stream(id)' > <div class='more'></div> <div class='message'> <div class='message-image'> <img height='48' width='48' src='http://a3.twimg.com/profile_images/1107286845/DW_speaking_normal.jpg'> </div> <div class='user-info-content'> <div class='user-info-row'> <span class='user-name'> <a class='user-nickname' href='javascript:void(false)'>"
				+ user.nickname
				+ "</a> <span class='user-realname'>"
				+ user.realname
				+ "</span></span></div> <div class='user-info-row'> <div class='email-info'> <span style='font-size: 17px !important; font-weight : bold'>Email:</span> "
				+ user.email
				+ "</div></div> <div class='user-info-row'> <div class='user-intro'>"
				+ user.intro
				+ "</div> </div> </div> <div class='function-button-bar'> <a href='javascript:void(false)' class='css3button' class='follow-button'>"
				+ follow_html
				+ "<span class='rss icon'></span>Subscribe to RSS Feed</a> <a href='javascript:void(false)' class='css3button'><span class='mail icon'></span>Send Letter</a> </div> </div> </div>";
		$("#user-stream-manager .stream").append(html);
	}
}

function load_new_tab(id) {
	switch (id) {
	case "message-stream-manager":
		break;
	case "group-stream-manager":
		$.ajax({
			type : "GET",
			url : "servlet/GetConcernGroups",
			data : "id=" + userID,
			success : function(msg) {
				generateGroups(msg);
			}
		});
		already_load[1] = true;
		break;
	case "user-stream-manager":
		$.ajax({
			type : "GET",
			url : "servlet/GetConcernUser",
			data : "id=" + userID,
			success : function(msg) {
				generateUsers(msg);
			}
		});
		already_load[2] = true;
		break;
	case "favorites-stream-manager":
		already_load[3] = true;
		break;
	}
}
